<?php

class AjaxController extends Zend_Controller_Action
{
    public function init()
    {
        if ($this->getRequest()->isXmlHttpRequest()) {
            Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
            $this->_helper->layout->disableLayout();
        }
    }

    public function getgoodAction()
    {
        $id   = (int) $this->_getParam('id');
        $type = $this->_getParam('type');

        if (!($id && $type)) {
            return false;
        }

        $good = Application_Model_Factory::getGood($id, $type);

        if (!$good) {
            return false;
        }

        $this->view->good = $good;
        $this->render('good');
        return true;
    }

    public function popuprentstockAction()
    {
        $this->render('rent-stock');
        return true;
    }

    public function saverentstockAction()
    {

        $name  = $this->_getParam('name');
        $phone = $this->_getParam('phone');
        file_put_contents('log_stock_rent.txt', $name . ' | ' . $phone . ' | '. date('Y-m-d H:i:s') . ' | ' .  PHP_EOL, FILE_APPEND);
        $headers = "From: <pihterev@list.ru>";
        $headers .= "Content-type: text/plain; charset='utf-8'";
        mail('kuzubtv@truds.ru', 'Заяка на получение скидки на аренду оборудования', 'Имя: ' . $name . '</br>Телефон: '  . $phone . '</br>', $headers);
        return true;
    }
}